//
//  AXFSuperMarketRightTableViewCell.m
//  AIXF
//
//  Created by Macx on 2017/7/10.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "AXFSuperMarketRightTableViewCell.h"
#import <UIImageView+WebCache.h>
@interface AXFSuperMarketRightTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *goodImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *specificsLabel;
@property (weak, nonatomic) IBOutlet UILabel *partner_price;
@property (weak, nonatomic) IBOutlet UILabel *maketPriceLabel;
@property (weak, nonatomic) IBOutlet UIButton *increseButton;
@property (weak, nonatomic) IBOutlet UIButton *reduceButton;
@property (weak, nonatomic) IBOutlet UILabel *orderNumLabel;

@end

@implementation AXFSuperMarketRightTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (IBAction)increaseAction:(id)sender {
    
    self.orderNum++;
    
    _rightModel.count = self.orderNum;
    
    self.clickIncrement = NO;
    
    CGPoint center = self.goodImageView.center;
    
    CGPoint convertPoint = [self.goodImageView convertPoint:center toView:kWindow];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:kIncrementRightNotification object:nil userInfo:@{@"point":[NSValue valueWithCGPoint:convertPoint], @"model":_rightModel}];
    
}


- (void)setOrderNum:(int)orderNum
{
    _orderNum = orderNum;
    
    self.orderNumLabel.text = [NSString stringWithFormat:@"%d", orderNum];
    
    /**
     hidden = YES; 非0的时候是隐藏的
     */
    self.reduceButton.hidden = !orderNum;
    
    self.orderNumLabel.hidden = !orderNum;
    
    _rightModel.count = orderNum;
    
}
- (IBAction)reduceAction:(id)sender {
    
    self.orderNum--;
    
    _rightModel.count = self.orderNum;
    
    self.clickIncrement = YES;
    
     [[NSNotificationCenter defaultCenter] postNotificationName:kDecrementRightNotification object:_rightModel];
}

- (void)setRightModel:(AXFHomeFirstSellModel *)rightModel
{
    _rightModel = rightModel;
    

    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self.goodImageView sd_setImageWithURL:[NSURL URLWithString:rightModel.img]];
        
        
        self.nameLabel.text = rightModel.name;
        self.specificsLabel.text = rightModel.specifics;
        self.partner_price.text = rightModel.price;
        self.maketPriceLabel.text = rightModel.market_price;
        self.orderNumLabel.hidden = rightModel.count;
        
        self.reduceButton.hidden = !rightModel.count;
        
        self.orderNumLabel.hidden = !rightModel.count;
        
        self.orderNumLabel.text = [NSString stringWithFormat:@"%d", rightModel.count];
        
    });
    
    
}

@end
